with Interfaces.C; use Interfaces.C;
with System;
with SDL_stdinc_h;

package SDL_mutex_h is


  SDL_MUTEX_TIMEDOUT : constant := 1;  --  SDL_mutex.h:43
  --  unsupported macro: SDL_MUTEX_MAXWAIT (~(Uint32)0)
  --  arg-macro: procedure SDL_LockMutex (m)
  --    SDL_mutexP(m)
  --  arg-macro: procedure SDL_UnlockMutex (m)
  --    SDL_mutexV(m)

  --    SDL - Simple DirectMedia Layer
  --    Copyright (C) 1997-2006 Sam Lantinga
  --    This library is free software; you can redistribute it and/or
  --    modify it under the terms of the GNU Lesser General Public
  --    License as published by the Free Software Foundation; either
  --    version 2.1 of the License, or (at your option) any later version.
  --    This library is distributed in the hope that it will be useful,
  --    but WITHOUT ANY WARRANTY; without even the implied warranty of
  --    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  --    Lesser General Public License for more details.
  --    You should have received a copy of the GNU Lesser General Public
  --    License along with this library; if not, write to the Free Software
  --    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  --    Sam Lantinga
  --    slouken@libsdl.org
  -- 

  -- Functions to provide thread synchronization primitives
  --	These are independent of the other SDL routines.
  -- 

  -- Set up for C function definitions, even when using C++  
  -- Synchronization functions which can time out return this value
  --   if they time out.
  -- 

  -- This is the timeout value which corresponds to never time out  
  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- Mutex functions                                                
  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- The SDL mutex structure, defined in SDL_mutex.c  
   --  skipped empty struct SDL_mutex

  -- Create a mutex, initialized unlocked  
   function SDL_CreateMutex return System.Address;  -- SDL_mutex.h:58:57
   pragma Import (C, SDL_CreateMutex, "SDL_CreateMutex");

  -- Lock the mutex  (Returns 0, or -1 on error)  
   function SDL_mutexP (mutex : System.Address) return int;  -- SDL_mutex.h:62:56
   pragma Import (C, SDL_mutexP, "SDL_mutexP");

  -- Unlock the mutex  (Returns 0, or -1 on error)
  --   It is an error to unlock a mutex that has not been locked by
  --   the current thread, and doing so results in undefined behavior.
  --  

   function SDL_mutexV (mutex : System.Address) return int;  -- SDL_mutex.h:69:56
   pragma Import (C, SDL_mutexV, "SDL_mutexV");

  -- Destroy a mutex  
   procedure SDL_DestroyMutex (mutex : System.Address);  -- SDL_mutex.h:72:63
   pragma Import (C, SDL_DestroyMutex, "SDL_DestroyMutex");

  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- Semaphore functions                                            
  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- The SDL semaphore structure, defined in SDL_sem.c  
   --  skipped empty struct SDL_semaphore

   --  skipped empty struct SDL_sem

  -- Create a semaphore, initialized with value, returns NULL on failure.  
   function SDL_CreateSemaphore (initial_value : SDL_stdinc_h.Uint32) return System.Address;  -- SDL_mutex.h:84:75
   pragma Import (C, SDL_CreateSemaphore, "SDL_CreateSemaphore");

  -- Destroy a semaphore  
   procedure SDL_DestroySemaphore (sem : System.Address);  -- SDL_mutex.h:87:63
   pragma Import (C, SDL_DestroySemaphore, "SDL_DestroySemaphore");

  -- This function suspends the calling thread until the semaphore pointed 
  -- * to by sem has a positive count. It then atomically decreases the semaphore
  -- * count.
  --  

   function SDL_SemWait (sem : System.Address) return int;  -- SDL_mutex.h:93:53
   pragma Import (C, SDL_SemWait, "SDL_SemWait");

  -- Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
  --   SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
  -- 

   function SDL_SemTryWait (sem : System.Address) return int;  -- SDL_mutex.h:98:56
   pragma Import (C, SDL_SemTryWait, "SDL_SemTryWait");

  -- Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
  --   the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
  --   the allotted time, and -1 on error.
  --   On some platforms this function is implemented by looping with a delay
  --   of 1 ms, and so should be avoided if possible.
  -- 

   function SDL_SemWaitTimeout (sem : System.Address; ms : SDL_stdinc_h.Uint32) return int;  -- SDL_mutex.h:106:71
   pragma Import (C, SDL_SemWaitTimeout, "SDL_SemWaitTimeout");

  -- Atomically increases the semaphore's count (not blocking), returns 0,
  --   or -1 on error.
  --  

   function SDL_SemPost (sem : System.Address) return int;  -- SDL_mutex.h:111:53
   pragma Import (C, SDL_SemPost, "SDL_SemPost");

  -- Returns the current count of the semaphore  
   function SDL_SemValue (sem : System.Address) return SDL_stdinc_h.Uint32;  -- SDL_mutex.h:114:57
   pragma Import (C, SDL_SemValue, "SDL_SemValue");

  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- Condition variable functions                                   
  -- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  -- The SDL condition variable structure, defined in SDL_cond.c  
   --  skipped empty struct SDL_cond

  -- Create a condition variable  
   function SDL_CreateCond return System.Address;  -- SDL_mutex.h:126:55
   pragma Import (C, SDL_CreateCond, "SDL_CreateCond");

  -- Destroy a condition variable  
   procedure SDL_DestroyCond (cond : System.Address);  -- SDL_mutex.h:129:60
   pragma Import (C, SDL_DestroyCond, "SDL_DestroyCond");

  -- Restart one of the threads that are waiting on the condition variable,
  --   returns 0 or -1 on error.
  --  

   function SDL_CondSignal (cond : System.Address) return int;  -- SDL_mutex.h:134:58
   pragma Import (C, SDL_CondSignal, "SDL_CondSignal");

  -- Restart all threads that are waiting on the condition variable,
  --   returns 0 or -1 on error.
  --  

   function SDL_CondBroadcast (cond : System.Address) return int;  -- SDL_mutex.h:139:61
   pragma Import (C, SDL_CondBroadcast, "SDL_CondBroadcast");

  -- Wait on the condition variable, unlocking the provided mutex.
  --   The mutex must be locked before entering this function!
  --   The mutex is re-locked once the condition variable is signaled.
  --   Returns 0 when it is signaled, or -1 on error.
  --  

   function SDL_CondWait (cond : System.Address; mut : System.Address) return int;  -- SDL_mutex.h:146:72
   pragma Import (C, SDL_CondWait, "SDL_CondWait");

  -- Waits for at most 'ms' milliseconds, and returns 0 if the condition
  --   variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
  --   signaled in the allotted time, and -1 on error.
  --   On some platforms this function is implemented by looping with a delay
  --   of 1 ms, and so should be avoided if possible.
  -- 

   function SDL_CondWaitTimeout
     (cond : System.Address;
      mutex : System.Address;
      ms : SDL_stdinc_h.Uint32) return int;  -- SDL_mutex.h:154:92
   pragma Import (C, SDL_CondWaitTimeout, "SDL_CondWaitTimeout");

  -- Ends C function definitions when using C++  
end SDL_mutex_h;
